package String;

import java.util.Scanner;

public class Stringtest4 {
    public static void main(String[] args) {
        //1、定义正确的登录名称和密码
        String okLoginName = "admin";
        String okPassword = "itheima";

        //2、定义一个循环，循环三次，让用户登录
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            System.out.println("输入登录名称");
            String loginName = sc.next();
            System.out.println("输入登录密码");
            String password = sc.next();

            //3、判断登录是否成功
            if(okLoginName. equals(loginName)){
                //4、判断密码是否正确
                if(okLoginName.equals(password)){
                    System.out.println("登录成功");
                    break;
                }else {
                    //密码错误
                    System.out.println("密码不正确，剩余" + (3 - i) + "次机会登录");
                }

            }else  {
                System.out.println("输入登录名称不正确，剩余" + (3-i) +"次机会登录");
            }

        }
    }
}
